<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>
<style>
    .layui-input-inline {
        width: 400px !important;
    }

    .s{
        clear:both;
        margin-top: 10px
    }
</style>

<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

                        <ul class="layui-tab-title">
                            <li onclick="go('stage?id='+'{$Request.param.pid}')">施工阶段</li>
                            <li class="layui-this" onclick="location.reload()">编辑阶段</li>
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">
                            <div class="layui-tab-item layui-show" style="padding-top: 15px">
                                <form class="layui-form " action="">
                                    <input type="hidden" name="id" value="{$item.id}">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">项目进度</label>
                                        <div class="layui-input-block">
                                            <select name="title" lay-verify="required" id="title">
                                                <option value="">请选择一个进度</option>
                                                <option value="水电工程">水电工程</option>
                                                <option value="拆除工程">拆除工程</option>
                                                <option value="瓦工工程">瓦工工程</option>
                                                <option value="油工工程">油工工程</option>
                                                <option value="木作安装">木作安装</option>
                                                <option value="竣工保洁">竣工保洁</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">开始时间</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" id="time" name="start_time" value="{$item.start_time}" placeholder="请输入"
                                                   lay-verify="required">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">工价</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" name="price" placeholder="请输入" value="{$item.price}"
                                                   lay-verify="required">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">工种</label>
                                        <div class="layui-input-block">


                                            <input type="checkbox" name="wt" title="拆除工"  value="拆除工">




                                            <input type="checkbox" name="wt" title="地板工"  value="地板工">




                                            <input type="checkbox" name="wt" title="水电工"  value="水电工">


                                            <input type="checkbox" name="wt" title="找平工"  value="找平工">


                                            <input type="checkbox" name="wt" title="安装工"  value="安装工">




                                            <input type="checkbox" name="wt" title="保洁工"  value="保洁工">

                                            <input type="checkbox" name="wt" title="木&nbsp;&nbsp;&nbsp;工"  value="木工" >

                                            <input type="checkbox" name="wt" title="瓦&nbsp;&nbsp;&nbsp;工"  value="瓦工">

                                            <br>

                                            <input type="checkbox" name="wt" title="吊顶工"  value="吊顶工">

                                            <input type="checkbox" name="wt" title="壁纸工"  value="壁纸工">

                                            <input type="checkbox" name="wt" title="辅助工" value="辅助工">


                                            <input type="checkbox" name="wt" title="维修工"  value="维修工">


                                            <input type="checkbox" name="wt" title="木作工"  value="木作工">
                                            <input type="checkbox" name="wt" title="台面工"  value="台面工">
                                            <input type="checkbox" name="wt" title="油&nbsp;&nbsp;&nbsp;工" value="油工">
                                            <input type="checkbox" name="wt" title="壁布工"  value="壁布工">

                                        </div>

                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">材料</label>
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn " id="cailiao" onclick="edit_select_material()">
                                                {{cailiao}}
                                            </button>
                                        </div>

                                    </div>



                                    <div class="layui-form-item form-footer2">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" type="button" lay-submit lay-filter="edit_stage">立即提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>


<script>
    var pid="{$Request.param.pid}";
    console.log(pid);

    var app = new Vue({
        el: '#app',
        data: {
            cailiao:"选择",
        },
    });
    //点亮复选框
    var re="{$item.worker_type}";
   var check=re.split(",");
    var groupCheckbox = $("input[name='wt']");
    $(function () {

        for (var i = 0; i < groupCheckbox.length; i++) {
            var val =groupCheckbox[i].value;
            if( check.indexOf(val)!=-1){
                groupCheckbox[i].checked=true;
            }
        }

        var s="";
        if('{$s}'){
            s='{$s}'
            var ma= eval('('+s+')');
            layui.data('egood', {
                key: 'egoodList',
                value: ma
            });
        }
    });

    layui.use(['form', 'upload', 'laydate'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;

        //网站设置
        //监听submit提交
        form.on('submit(edit_stage)', function (obj) {
            var worker ="";
            var groupCheckbox=$("input[name='wt']");
            // console.log("c"+groupCheckbox[0]);
            for(var i=0;i<groupCheckbox.length;i++){
                if(groupCheckbox[i].checked){
                    var val =groupCheckbox[i].value;
                    // console.log("c1223"+val);
                    if(worker.length>0){
                        worker+=","+val;
                    }else{
                        worker+=val;
                    }

                }
            }
            obj.field["worker_type"]=worker;
            var localGood = layui.data('egood');

            obj.field["material"] =[];
            if(!jQuery.isEmptyObject(localGood.egoodList)){
                obj.field["material"]=localGood.egoodList;
            }
            obj.field["project_id"]=pid;
//            layer.msg(JSON.stringify(obj.field)); obj.field为当前容器的全部表单字段，名值对形式：{name: value}
            $.post("{:url('edit_stage')}", obj.field,function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1});
                    layui.data('egood', null);
                    return false;
                } else {
                    layer.msg(res.msg, {icon: 2}, function () {

                    })
                    return false;
                }

            });
            return false;
        });
        //拖拽上传
        upload.render({
            elem: '#pic1'
            , url: '/tool/qiniu/upload'
            , before: function () {
                layer.load(2);
            }
            , done: function (res) {
                layer.closeAll();
                console.log(res)
                $('#pic1 img').attr('src', res.data.url);//完整url
                $('#pic1 input').val(res.data.pic);//存入数据库中的部分url
            }
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#time' //指定元素
        });
    });
    function edit_select_material(){
        var sid="{$Request.param.id}";
        layer.open({
            type: 2,
            title: '材料',
            shadeClose: true,
            shade: 0.01,
            area: ['80%', '80%'],
            content: "{:url('edit_select_material')}?id="+sid,
        });
    }
    //设置选择状态
    function setSelect(ele, val) {

        $('#' + ele + ' option').each(function (index, ele) {
            var el = $(ele);
            if (el.attr('value') == val) {
                el.attr('selected', 'selected')
            } else {
                el.removeAttr('selected');
            }
        })

    }

    $(function () {
        setSelect('title', "{$item.title}")
    });

</script>
</body>
</html>